<template>
	<view class="page">
		<view class="promotional-information">
			<view class="left-info">
				<image class="person-avatar" mode="aspectFill" :src="rankInfo.avatar"></image>
				<view class="username">{{ rankInfo.nickName }}</view>
			</view>
			<view>
				<view class="ranking">No.{{ rankInfo.ranking }}</view>
				<view class="num">昨日佣金：￥{{ rankInfo.amount }}</view>
			</view>
		</view>
		<view class="person-list">
			<view class="person-item" v-for="(item, index) in rankList" :key="index">
				<view class="left-info">
					<image v-if="item.ranking == 1" class="rank-image" mode="aspectFill" src="/static/images/one@2x.png">
					</image>
					<image v-if="item.ranking == 2" class="rank-image" mode="aspectFill" src="/static/images/two@2x.png">
					</image>
					<image v-if="item.ranking == 3" class="rank-image" mode="aspectFill" src="/static/images/three@2x.png">
					</image>
					<view class="rank-num" v-if="item.ranking > 3">{{ item.ranking }}</view>
					<image class="person-avatar" mode="aspectFill" :src="item.avatar || '/static/images/default_avatar.png'">
					</image>
					<view class="person-name">{{ item.nickName }}</view>
				</view>
				<view class="right-info">{{ item.amount }}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getMyRanking,
		getRankingList
	} from '@/apis/request.js';

	export default {
		data() {
			return {
				params: {
					pageNo: 1,
					pageSize: 15,
					type: 1
				},
				rankInfo: '',
				rankList: []
			};
		},
		methods: {
			//我的排行
			getMyRanking() {
				getMyRanking({
					type: 1 //类型 0推广 1佣金
				}).then(res => {
					this.rankInfo = res;
				});
			},
			//排行列表
			getList() {
				getRankingList(this.params).then(res => {
					if (this.params.pageNo == 1) {
						this.rankList = res.records;
					} else {
						if (this.rankList.length < res.total) {
							this.rankList = this.rankList.concat(res.records);
						} else {
							this.rankList = this.rankList;
						}
					}
				});
			}
		},
		onLoad() {
			this.getMyRanking();
			this.getList();
		},
		onReachBottom() {
			this.params.pageNo++;
			this.getList();
		},
		onPullDownRefresh() {
			this.params.pageNo = 1;
			this.rankList = [];
			this.getList();
			uni.stopPullDownRefresh();
		}
	};
</script>

<style lang="scss" scoped>
	.page {
		background-color: #f2f2f2ff;
		height: 100%;
		min-height: 100vh;

		.promotional-information {
			display: flex;
			align-items: center;
			justify-content: space-between;
			box-sizing: border-box;
			height: 150rpx;
			width: 750rpx;
			padding: 0 32rpx;
			background: linear-gradient(0deg, #32C59A, #1a689fff);

			.person-avatar {
				width: 70rpx;
				height: 70rpx;
				border-radius: 50%;
			}

			.left-info {
				display: flex;
				align-items: center;
			}

			.username {
				margin-left: 16rpx;
				color: #fff;
				font-size: 28rpx;
			}

			.ranking {
				font-size: 24rpx;
				color: #d3e0fb;
			}

			.num {
				font-size: 24rpx;
				color: #d3e0fb;
				margin-top: 14rpx;
			}
		}

		.person-list {
			background-color: #fff;

			.person-item {
				padding: 30rpx;
				border-bottom: 2rpx solid #ececec;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.left-info {
					display: flex;
					align-items: center;

					.rank-image {
						width: 56rpx;
						height: 44rpx;
					}

					.person-avatar {
						background-color: #ececec;
						margin-left: 30rpx;
						width: 70rpx;
						height: 70rpx;
						border-radius: 50%;
					}

					.person-name {
						font-size: 28rpx;
						margin-left: 20rpx;
					}

					.rank-num {
						font-weight: 900;
						font-size: 36rpx;
						color: #aaaaaa;
					}
				}

				.right-info {
					font-size: 32rpx;
				}
			}
		}
	}
</style>